package ru.bragnikita.utils.swing.dbpanel;

import ru.bragnikita.utils.swing.utils.PanelTest;
import ru.bragnikita.utils.swing.widget.dialog.ValueDialog;

import javax.swing.*;
import java.awt.*;

/**
 * @author Nikita.Brazhnikov
 */
public class DatabaseNameDialog extends ValueDialog<String> {

    private JTextField textField;


    public DatabaseNameDialog(Window parent) {
        super(parent, "Database name", null);
    }

    @Override
    protected String collectData(String model) {
        return textField.getText();
    }

    @Override
    protected Component createPanel(JPanel panel, String model) {
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        textField = new JTextField(20);
        textField.setAlignmentX(0.0f);
        final JLabel label = new JLabel("Database name");
        label.setAlignmentX(0.0f);
        panel.add(label);
        panel.add(textField);
        panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        return panel;
    }

    public static void main(String[] args) {
        final JFrame frame = PanelTest.createFrame();
        DatabaseNameDialog dialog = new DatabaseNameDialog(frame);
        String res = dialog.request();
        System.out.println(res);
        frame.dispose();
    }
}
